package com.wjc.demo.config;

import com.wjc.demo.interceptor.FirstInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ Description：TODO
 * @ Author：wzj
 * @ Date：2019/3/10 17:42
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    //必须在FirstInterceptor上添加@Component或@Configuration注解，注入IOC才行，
    //直接把addInterceptors方法中的firstInterceptor换成new FirstInterceptor()不可用
    @Autowired
    private FirstInterceptor firstInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        System.out.println("InterceptorConfig");
        registry.addInterceptor(firstInterceptor).addPathPatterns("/**") // /**匹配所有请求
        .excludePathPatterns("/js/**");//放行js，否则前台报Uncaught ReferenceError: $ is not defined错误
    }
}
